#define _CRT_SECURE_NO_WARNINGS  1

class Solution {
public:
    bool IsPopOrder(vector<int>& pushV, vector<int>& popV) {
        stack<int> st;
        int popi = 0;
        int pushi = 0;
        while (pushi < pushV.size())
        {
            st.push(pushV[pushi++]);

            if (popV[popi] != st.top())
            {
                continue;
            }
            else
            {
                while (!st.empty() && popV[popi] == st.top())
                {
                    st.pop();
                    popi++;
                }
            }
        }
        return st.empty();
    }
};